package vip.xiaonuo.megvii.config.model;

import lombok.Data;

import javax.annotation.Resource;

@Data
public class ApiResponse {

    private Integer code;
    private String message;
    private Long timestamp;
    private Integer time_cost;
    private Object data;

    public ApiResponse(Integer code, String message, Long timestamp, Integer timeCost, Object data) {
        this.code = code;
        this.message = message;
        this.timestamp = timestamp;
        this.time_cost = timeCost;
        this.data = data;
    }

    public static ApiResponse failed(){
        return failed(-1,"请求异常");
    }

    public static ApiResponse failed(int code){
        String message = ResponseCode.getMessage(code);
        return failed(code,message);
    }

    public static ApiResponse failed(int code,Object obj){
        String message = ResponseCode.getMessage(code);
        return failed(code,message,obj);
    }


    public static ApiResponse failed(int code,String message){
        return failed(code,message,null);
    }

    public static ApiResponse failed(int code,String message,Object data){
        return new ApiResponse(code,message,null,null,data);
    }

    public static ApiResponse success(){
        return success(null);
    }

    public static ApiResponse success(Object obj){
        return new ApiResponse(0,"请求成功",null,null,obj);
    }


    public boolean isSuccess(){
        return this.code == 0;
    }


}
